package com.jiuxian.scheduling.commons;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * Created by wangjingqing on 2017/12/18.
 */
public class SpringApplicationContext implements ApplicationContextAware {
    static ApplicationContext applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringApplicationContext.applicationContext = applicationContext;
    }

    /**
     * 根据名称获取实体类<br>
     * @param name
     * @return
     */
    public static Object getClass(String name){
        return applicationContext.getBean(name);
    }

    /**
     * 根据类型获取实体类<br>
     * @param tClass
     * @param <T>
     * @return
     */
    public static <T> T getClass(Class<T> tClass){
        return applicationContext.getBean(tClass);
    }
}
